﻿<UserControl
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:resx="clr-namespace:iTuner.Properties"
  mc:Ignorable="d"
  x:Class="iTuner.DeviceSelector"
  x:ClassModifier="internal"
  xmlns:local="clr-namespace:iTuner"
  x:Name="UserControl" Background="Transparent"
  d:DesignWidth="340" d:DesignHeight="220">

  <UserControl.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="..\Controls\iStyles.xaml"/>
        <ResourceDictionary Source="..\Controls\DetailPanelStyles.xaml"/>
        <ResourceDictionary x:Name="strings" />
      </ResourceDictionary.MergedDictionaries>

      <local:UsbNullConverter x:Key="UsbNullConverter" />
      <local:UsbSpaceConverter x:Key="UsbSpaceConverter" />

      <Style TargetType="TextBlock">
        <Setter Property="FontSize" Value="13"/>
        <Setter Property="FontFamily" Value="Calibri"/>
      </Style>
      <Style TargetType="TextBox" BasedOn="{StaticResource TextBoxStyle}">
        <Setter Property="FontSize" Value="13"/>
        <Setter Property="FontFamily" Value="Calibri"/>
      </Style>
      <Style TargetType="ComboBox">
        <Setter Property="FontSize" Value="13"/>
        <Setter Property="FontFamily" Value="Calibri"/>
      </Style>

      <BorderGapMaskConverter x:Key="BorderGapMaskConverter"/>
      <Style x:Key="GroupBoxStyle" TargetType="{x:Type GroupBox}">
        <Setter Property="BorderBrush" Value="#D5DFE5"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="{x:Type GroupBox}">
              <Grid SnapsToDevicePixels="true">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="6"/>
                  <ColumnDefinition Width="Auto"/>
                  <ColumnDefinition Width="*"/>
                  <ColumnDefinition Width="6"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                  <RowDefinition Height="Auto"/>
                  <RowDefinition Height="Auto"/>
                  <RowDefinition Height="*"/>
                  <RowDefinition Height="6"/>
                </Grid.RowDefinitions>
                <Border Background="{TemplateBinding Background}" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4" Grid.Column="0" Grid.ColumnSpan="4" Grid.Row="1" Grid.RowSpan="3"/>
                <Border x:Name="Header" Padding="3,1,3,0" Grid.Column="1" Grid.Row="0" Grid.RowSpan="2">
                  <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header" RecognizesAccessKey="True"/>
                </Border>
                <ContentPresenter Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="2"/>
                <Border BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4" Grid.ColumnSpan="4" Grid.Row="1" Grid.RowSpan="3">
                  <Border.OpacityMask>
                    <MultiBinding Converter="{StaticResource BorderGapMaskConverter}" ConverterParameter="7">
                      <Binding Path="ActualWidth" ElementName="Header"/>
                      <Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}"/>
                      <Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}"/>
                    </MultiBinding>
                  </Border.OpacityMask>
                  <Border BorderBrush="#FF808080" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3">
                    <Border BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2"/>
                  </Border>
                </Border>
              </Grid>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>
    </ResourceDictionary>
  </UserControl.Resources>

  <StackPanel Orientation="Vertical">

    <GroupBox Style="{DynamicResource GroupBoxStyle}">
      <GroupBox.Header>
        <TextBlock Text="{x:Static resx:Resources.DeviceSelector_Attached}"/>
      </GroupBox.Header>

      <Grid Margin="2">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <ComboBox
          x:Name="devicesBox" DisplayMemberPath="Description"
          Grid.ColumnSpan="2" Margin="0,0,0,4"
          MinWidth="200" Width="Auto" HorizontalAlignment="Stretch"
          SelectionChanged="DoDeviceSelectionChanged"/>

        <TextBlock
          Text="{x:Static resx:Resources.DeviceSelector_Drive}" Grid.Row="1" Margin="3,1,5,1" FontWeight="Bold"
          VerticalAlignment="Center" HorizontalAlignment="Right" />
        <TextBlock
          Text="{Binding Path=SelectedItem.Name, ElementName=devicesBox, Converter={StaticResource UsbNullConverter}, Mode=OneWay}"
          Grid.Row="1" Grid.Column="1" Margin="0,1,5,1"
          VerticalAlignment="Center"/>

        <TextBlock
          Text="{x:Static resx:Resources.DeviceSelector_Model}" Grid.Row="2" Margin="3,1,5,1" FontWeight="Bold"
          VerticalAlignment="Bottom" HorizontalAlignment="Right" />
        <TextBlock
          Text="{Binding Path=SelectedItem.Model, ElementName=devicesBox, Converter={StaticResource UsbNullConverter}, Mode=OneWay}"
          TextTrimming="CharacterEllipsis"
          Grid.Row="2" Grid.Column="1" Margin="0,1,5,1"
          VerticalAlignment="Center"/>

        <TextBlock
          Text="{x:Static resx:Resources.DeviceSelector_Free}" Grid.Row="3" Margin="3,1,5,0" FontWeight="Bold"
          VerticalAlignment="Bottom" HorizontalAlignment="Right" />
        <TextBlock
          Text="{Binding Path=SelectedItem.Space, ElementName=devicesBox, Converter={StaticResource UsbSpaceConverter}, Mode=OneWay}"
          Grid.Row="3" Grid.Column="1" Margin="0,1,5,0"
          VerticalAlignment="Center"/>
      </Grid>
    </GroupBox>

    <GroupBox Style="{DynamicResource GroupBoxStyle}" Margin="0,8,0,0" Padding="2,2,2,4">
      <GroupBox.Header>
        <CheckBox
          x:Name="autoDetectBox" IsChecked="True" Grid.ColumnSpan="2"
          HorizontalAlignment="Left" VerticalAlignment="Bottom"
          Content="{x:Static resx:Resources.DeviceSelector_AutoDetect}"
          Click="DoAutoDetectChanged" />
      </GroupBox.Header>

      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <TextBlock
          Text="{x:Static resx:Resources.DeviceSelector_Target}" Grid.Row="1" Margin="2,8,4,0"
          VerticalAlignment="Center" FontWeight="Bold"
          HorizontalAlignment="Right" />
        <TextBox
          x:Name="locationBox" Text="\" Margin="0,8,0,0"
          Grid.Row="1" Grid.Column="1" VerticalContentAlignment="Center"
          Style="{DynamicResource TextBoxStyle}" IsEnabled="False" />
        <Button
          x:Name="selectFolderButton"
          Content="..." Click="DoSelectFolder" Grid.Row="1" Grid.Column="2"
          Width="20" HorizontalAlignment="Right" IsEnabled="False"
          Style="{StaticResource iButtonStyle}" Margin="4,8,0,0" />

        <TextBlock
          Text="{x:Static resx:Resources.DeviceSelector_Layout}" Grid.Row="2" Margin="2,3,4,0"
          VerticalAlignment="Center" FontWeight="Bold"
          HorizontalAlignment="Right" />
        <ComboBox
          x:Name="formatBox" Grid.Row="2" Grid.Column="1" Margin="0,3,0,0" IsEnabled="False"
          HorizontalAlignment="Stretch" SelectedIndex="0">
          <ComboBoxItem Tag="R_L_T">
            <TextBlock>
              <Run Text="{x:Static resx:Resources.DeviceSelector_Artist}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Album}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Title}"/>
            </TextBlock>
          </ComboBoxItem>
          <ComboBoxItem Tag="R_LT">
            <TextBlock>
              <Run Text="{x:Static resx:Resources.DeviceSelector_Artist}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Album}"
                   /> - <Run Text="{x:Static resx:Resources.DeviceSelector_Title}"/>
            </TextBlock>
          </ComboBoxItem>
          <ComboBoxItem Tag="RLT">
            <TextBlock>
              <Run Text="{x:Static resx:Resources.DeviceSelector_Artist}"
                   /> - <Run Text="{x:Static resx:Resources.DeviceSelector_Album}"
                   /> - <Run Text="{x:Static resx:Resources.DeviceSelector_Title}"/>
            </TextBlock>
          </ComboBoxItem>
          <ComboBoxItem Tag="R_T">
            <TextBlock>
              <Run Text="{x:Static resx:Resources.DeviceSelector_Artist}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Title}"/>
            </TextBlock>
          </ComboBoxItem>
          <ComboBoxItem Tag="L_R_T">
            <TextBlock>
              <Run Text="{x:Static resx:Resources.DeviceSelector_Album}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Artist}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Title}"/>
            </TextBlock>
          </ComboBoxItem>
          <ComboBoxItem Tag="L_RT">
            <TextBlock>
              <Run Text="{x:Static resx:Resources.DeviceSelector_Album}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Artist}"
                   /> - <Run Text="{x:Static resx:Resources.DeviceSelector_Title}"/>
            </TextBlock>
          </ComboBoxItem>
          <ComboBoxItem Tag="L_T">
            <TextBlock>
              <Run Text="{x:Static resx:Resources.DeviceSelector_Album}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Title}"/>
            </TextBlock>
          </ComboBoxItem>
          <ComboBoxItem Tag="G_R_T">
            <TextBlock>
              <Run Text="{x:Static resx:Resources.DeviceSelector_Playlist}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Album}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Artist}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Title}"/>
            </TextBlock>
          </ComboBoxItem>
          <ComboBoxItem Tag="G_RT">
            <TextBlock>
              <Run Text="{x:Static resx:Resources.DeviceSelector_Genre}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Artist}"
                   /> - <Run Text="{x:Static resx:Resources.DeviceSelector_Title}"/>
            </TextBlock>
          </ComboBoxItem>
          <ComboBoxItem Tag="P_L_R_T">
            <TextBlock>
              <Run Text="{x:Static resx:Resources.DeviceSelector_Playlist}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Album}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Artist}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Title}"/>
            </TextBlock>
          </ComboBoxItem>
          <ComboBoxItem Tag="P_L_RT">
            <TextBlock>
              <Run Text="{x:Static resx:Resources.DeviceSelector_Playlist}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Album}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Artist}"
                   /> - <Run Text="{x:Static resx:Resources.DeviceSelector_Title}"/>
            </TextBlock>
          </ComboBoxItem>
          <ComboBoxItem Tag="P_R_L_T">
            <TextBlock>
              <Run Text="{x:Static resx:Resources.DeviceSelector_Playlist}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Artist}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Album}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Title}"/>
            </TextBlock>
          </ComboBoxItem>
          <ComboBoxItem Tag="P_R_LT">
            <TextBlock>
              <Run Text="{x:Static resx:Resources.DeviceSelector_Playlist}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Artist}"
                   />\<Run Text="{x:Static resx:Resources.DeviceSelector_Album}"
                   /> - <Run Text="{x:Static resx:Resources.DeviceSelector_Title}"/>
            </TextBlock>
          </ComboBoxItem>
        </ComboBox>

      </Grid>
    </GroupBox>

  </StackPanel>
</UserControl>
